#!/bin/bash

url=cmis.foxitcloud.com:8180/cmis/atom
memoutfile=tomcat_mem_dump.hprof
LOG=/tmp/monitor_outmemory.log
time=`date +%Y%m%d`

getHttpCode ()
{
	HttpCode=`curl --silent -o /dev/null -w '%{http_code}' -H "Authorization: Bearer xxx,guest" $url`

	return $HttpCode
}

getTomcatPid ()
{
	Tomcat_pid=`ps -ef|grep -w bootstrap|grep -v grep|awk '{printf $2}'`
	return $Tomcat_pid
}



getHttpCode

getTomcatPid

if [ "$HttpCode"x != "200"x ];then
	echo "Tomcat Connecte Failed at `date`" | tee -a $LOG
su --shell=/bin/bash tomcat -c "jmap -dump:format=b,file=/tmp/${memoutfile}${time} ${Tomcat_pid}"
fi